package com.example.tabbar.fragment

import android.annotation.SuppressLint
import android.content.Context
import android.net.wifi.WifiManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.tabbar.adapter.RoomAdapter
import com.example.tabbar.databinding.FragmentModeRoomBinding
import com.example.tabbar.room.entity.Room


class ModeRoomFragment : Fragment() {
    private var binding: FragmentModeRoomBinding? = null
    private var recyclerView: RecyclerView? = null
    private var adapter: RoomAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentModeRoomBinding.inflate(inflater, container, false)
        return binding!!.root
    }
    @SuppressLint("MissingPermission")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recyclerView = binding!!.roomRecyclerView
        adapter = RoomAdapter()
        recyclerView!!.adapter = adapter
        recyclerView?.layoutManager = LinearLayoutManager(requireContext())
        recyclerView?.addItemDecoration(
            DividerItemDecoration(requireContext(),
                DividerItemDecoration.VERTICAL)
        )
        val list = createRoom()

        adapter?.setItems(list)
        val wifiManager = requireContext().getSystemService(Context.WIFI_SERVICE) as WifiManager
        wifiManager.setWifiEnabled(true)

    }


    private fun createRoom() : List<Room> {
        val list =
        listOf(
            Room(id = 1, area = "30m³", standard = "ISO", status = "正在测量", locCount = 5),
            Room(id = 2, area = "30m³", standard = "ISO", status = "正在测量", locCount = 5),
            Room(id = 3, area = "30m³", standard = "ISO", status = "正在测量", locCount = 6)
        )
        return list
    }

    companion object {

        @JvmStatic
        fun newInstance() =
            ModeRoomFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}